import { ui } from "../../ui/layaMaxUI";
import { PlatformType } from "../../core_wq/platforms/PlatformType";
import TestPlatform from "../../core_wq/platforms/TestPlatform";
import WeChatPlatform from "../../core_wq/platforms/WeChatPlatform";
import AppConfig from "../../core_wq/config/AppConfig";
import GlobalData from "../../core_wq/db/GlobalData";
import GameServerVO from "../../core_wq/db/vo/GameServerVO";
import GameStorage from "../../core_wq/game/GameStorage";
import Game from "../../core_wq/game/Game";
import WeaponVO from "../../core_wq/db/vo/WeaponVO";
import SoundVO from "../../core_wq/db/vo/SoundVO";
import SoundMgr from "../../core_wq/sound/SoundMgr";
import GameConfig from "../../GameConfig";
import MonsterSkillVO from "../../core_wq/db/vo/MonsterSkillVO";
import StopSkill from "../../core_wq/game/skill/monster/StopSkill";
import InvincibleSkill from "../../core_wq/game/skill/monster/InvincibleSkill";
import JumpMoveSkill from "../../core_wq/game/skill/monster/JumpMoveSkill";
import ShieldSkill from "../../core_wq/game/skill/monster/ShieldSkill";
import MoreLifeZoom from "../../core_wq/game/skill/monster/MoreLifeZoom";
import InvisibleSkill from "../../core_wq/game/skill/monster/InvisibleSkill";
import BlockSkill from "../../core_wq/game/skill/monster/BlockSkill";
import ScaleChangeSkill from "../../core_wq/game/skill/monster/ScaleChangeSkill";
import ChangeMovePosSkill from "../../core_wq/game/skill/monster/ChangeMovePosSkill";
import RandomSkill from "../../core_wq/game/skill/monster/RandomSkill";
 

export default class LoadingScene extends ui.moduleView.loading.LoadingSceneUI {

    private _isInit = false;

    constructor() {
        super();

    }

    onEnable() {
        if (this.txtText && this._isInit === false) {

            this._isInit = true;
            this.txtText.text = "0%";
            let res = GlobalData.Ins.getTotalStepCsvList().concat([]);
            GameStorage.loadStorage((isOK: boolean) => {
                console.log(" GameStorage.loadStorage ",Game.hero.playerData)
                Game.hero.playerData.heroResPath = "res/hero/" + Game.hero.playerData.heroId + "/hero" + Game.hero.playerData.heroId + ".lh";
                res.push("res/bullet/" + Game.hero.playerData.heroId + "/bullet" + Game.hero.playerData.heroId + ".lh")
                // res.push("res/hero/hero/hero.lh")
                res.push(Game.hero.playerData.heroResPath)
                // console.log(Game.hero.playerData.heroResPath)
                res.push("res/atlas/images/common.atlas");
                res.push("res/atlas/images/main.atlas");
                res.push("res/atlas/images/gameOver.atlas");
                res.push("res/atlas/images/sign.atlas")
                res.push("res/atlas/images/shop.atlas")
                res.push("res/map/map" + Game.hero.playerData.mapBgId + ".png")
           
                // console.log(res);
                Laya.loader.create(res, new Laya.Handler(this, this.onHandler), new Laya.Handler(this, this.onProgress));
            })
        }
    }

    private onHandler(): void {
        this.regClass();
        GlobalData.Ins.initCacheData();
        SoundMgr.Ins.loadRes();
        let gameServer: GameServerVO = GlobalData.getData(GlobalData.GameServerVO, 1)
        let BP = Laya.ClassUtils.getRegClass("p" + gameServer.platformType);
        console.log("current platform.." + gameServer.platformType)
        new BP().checkUpdate();
        Game.init();
        Game.sceneManager.showMain();
        this.removeSelf();
    }

    private onProgress(value: number): void {
        value = value * 100;
        this.txtText.text = "" + value.toFixed(0) + "%";
        // console.log(value)
    }

    private regClass() {
        var REG: Function = Laya.ClassUtils.regClass;

        //平台
        REG("p" + PlatformType.TEST, TestPlatform);
        REG("p" + PlatformType.WECHAT, WeChatPlatform);

        REG("MonsterSkill_10001",StopSkill);
        REG("MonsterSkill_10002",InvincibleSkill);
        REG("MonsterSkill_10003",JumpMoveSkill);
        REG("MonsterSkill_10004",ShieldSkill);
        REG("MonsterSkill_10005",MoreLifeZoom);
        REG("MonsterSkill_10006",InvisibleSkill);
        REG("MonsterSkill_10007",BlockSkill);
        REG("MonsterSkill_10008",ScaleChangeSkill);
        REG("MonsterSkill_10009",ChangeMovePosSkill);
        REG("MonsterSkill_10010",RandomSkill);
    }




}